package com.lxp.userms.service.impl;

import com.lxp.userms.entity.Question;
import com.lxp.userms.mapper.QuestionMapper;
import com.lxp.userms.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    private QuestionMapper questionMapper;

    @Override
    @Transactional
    public int publishQuestion(Question question) {
        return questionMapper.insertQuestion(question);
    }

    @Override
    public List<Question> getAllQuestions() {
        return questionMapper.selectAllQuestions();
    }

    @Override
    public List<Question> getQuestionsByUserId(int userId) {
        return questionMapper.selectQuestionsByUserId(userId);
    }

    @Override
    public List<Question> getQuestionsByExpertId(int expertId) {
        return questionMapper.selectQuestionsByExpertId(expertId);
    }

    @Override
    public List<Question> getQuestionsByCategoryId(int categoryId) {
        return questionMapper.selectQuestionsByCategoryId(categoryId);
    }

    @Override
    public Question getQuestionById(int id) {
        return questionMapper.selectQuestionById(id);
    }

    @Override
    @Transactional
    public int updateQuestion(Question question) {
        return questionMapper.updateQuestion(question);
    }

    @Override
    @Transactional
    public int deleteQuestion(int id) {
        return questionMapper.deleteQuestion(id);
    }

    @Override
    @Transactional
    public int deleteQuestionsByCategoryId(int categoryId) {
        return questionMapper.deleteQuestionsByCategoryId(categoryId);
    }
}